/*******************************************************************************
 * Level Master 2000
 * Copyright (C) 2010 Christian Herzog
 * For more information see http://code.google.com/p/levelmaster2000/
 *
 * This file is licensed under the terms of the MIT license, see
 * http://www.opensource.org/licenses/mit-license.php for further information.
 ******************************************************************************/

package com.zog
{
	import com.pblabs.engine.PBE;
    import com.pblabs.engine.debug.Logger;
    import com.pblabs.engine.entity.EntityComponent;
    import com.pblabs.engine.entity.PropertyReference;
    
    public class RandomNumber extends EntityComponent
    {
        public var min:Number = 0.0;
        public var max:Number = 1.0;
        
        public var numberProperty:PropertyReference = null;
        
        /**
         * This is the varying number to be used.
         */
        public function get randomNumber():Number
        {
            //TODO: this is not finished yet... see RandomPoint.
            //make numberProperty optional?
            if(numberProperty)
            {
                var newNumber:Number = owner.getProperty(numberProperty) as Number;
                
                var randX:Number = Math.random();
                var oneMinusRandX:Number = 1.0 - randX;
                var newX:Number = randX * max + oneMinusRandX * min;
            
                newNumber += newX;
                
                return newNumber;
            }
            else
            {
                Logger.error(this, "get number()", "Property " + numberProperty.toString() + " not found.");
                
                return 0.0;
            }
        }
        
        protected override function onAdd():void
        {
            super.onAdd();
        }
        
		protected override function onRemove():void
		{
			super.onRemove();
		}
    }
}